//条件变量的封装
#pragma once
#include <iostream>
#include <pthread.h>
#include "Mutex.hpp"

namespace CondModule
{
    using namespace LockMoudle;
    class Cond
    {
    public:
        Cond()
        {
            int n = ::pthread_cond_init(&_cond, nullptr);
            (void)n;
        }
        void wait(Mutex &mutex)//放入等待队列中, 第二个参数是让线程释放我们持有的锁
        {
            int n = ::pthread_cond_wait(&_cond,mutex.LockPtr());
            (void)n;
        }
        void Notify() //释放一个线程
        {
            int n = ::pthread_cond_signal(&_cond);
            (void)n;
        }
        void NotifAll() //释放所有线程
        {
            int n = ::pthread_cond_broadcast(&_cond);
            (void)n;
        }
        ~Cond()
        {
            int n = ::pthread_cond_destroy(&_cond);
            (void)n;
        }
    private:
        pthread_cond_t _cond; //定义一个条件变量
    };
}